package cz.possoft.client.gui.panel.nastavenispodnipanel.components;

import javax.swing.JComboBox;

import cz.possoft.client.gui.panel.GamePanel;
import cz.possoft.client.utils.GameInvocationUtils;
import cz.possoft.client.utils.PanelHolderUtils;

/**
  * Obsahuje seznam vsech her.
  * 
  * @author mara
  */
public class GamesComboBox extends JComboBox {
	
	public GamesComboBox() {
		super();
		for (String gameName : PanelHolderUtils.getDisplayNamesForAllGames()) {
			addItem(gameName);
		}
	}
	
	// vraci prefix vybrane hry - klic z mapy GameInvocationUtils
	// pro aktualni hodnotu v comboboxu.
	// napr. pro Sachy vraci 'Chess'.
	public String getPrefixForSelectedGame() {
		String gameValue = (String)this.getSelectedItem();
		for (String gameKey : PanelHolderUtils.getKeysForAllGames()) {
			String displayName = PanelHolderUtils.getDisplayNameByKey(gameKey);
			if (displayName.equals(gameValue)) {
				return gameKey;
			}
		}
		return null;
	}
	
	public void setValueAccordingToKey(String gameKey) {
		String displayName = PanelHolderUtils.getDisplayNameByKey(gameKey);
		setSelectedItem(displayName);
	}
}
